<%= form_for(@cultural_heritage_collection, :html=>{:onsubmit => "return validate(this);" }) do |f| %>
  <% if @cultural_heritage_collection.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(@cultural_heritage_collection.errors.count, "error") %> prohibited this cultural_heritage_collection from being saved:</h2>

      <ul>
      <% @cultural_heritage_collection.errors.full_messages.each do |msg| %>
        <li><%= msg %></li>
      <% end %>
      </ul>
    </div>
  <% end %>

<div class="shadow">
  <fieldset id="agrupacion" >
    <legend>Datos Básicos </legend>

      <fieldset class="column-left" >
        <div class="field">
          <%= f.label :name, "Nombre:" %>
          <%= f.text_field :name %>
        </div>

        <%#*<div class="field">%>
          <%#= f.label :current_size, "Tamaño actual:" %>
          <%#= f.text_field :current_size %>
        <%#*</div>%>

        <div class="field" id="cultural_heritage_collection_owner" >
          <%= f.label :owner, "Propietario:" %>
          <%=
            if @owners.blank?
              @owners = []
            end
              
            f.select :owner, @owners.collect { |t| [t.name+' '+t.lastname,t.id]}, {:include_blank=>"Seleccione"}, {:class => 'combobox'}            
          %>


        </div>
        <%#*<div class="field">%>
          <%#= f.label :state, "Estado:" %>
          <%#= f.select :state, @states.collect { |t| [t.name,t.id]}, {:include_blank=>"Seleccione"}, {:class => 'combobox'} %>

        <%#*</div>%>
        <div class="field">
          <%= f.label :cultural_institution, "Institución Cultural:" %>
          <%=
            if @cultural_institutions.blank?
              @cultural_institutions = []
            end

            f.select :cultural_institution, @cultural_institutions.collect { |t| [t.name,t.id]}, {:include_blank=>"Seleccione"}, {:class => 'combobox'}
          %>
        </div>

        <div class="field">
          <%= f.label :original_size, "Tamaño original en unidades:" %>
          <%= f.text_field :original_size %>
        </div>
      </fieldset>

      <fieldset class="column-right" >

        <div class="field">
          <%= f.label :description, "Descripción:" %>
          <%= f.text_area :description %>
        </div>

        <%#*<div class="field">%>
          <%#*<label>Añadir Fotos:</label>%>
          <%#= file_field_tag 'cultural_heritage_collection[photos][]', :id => 'cultural_heritage_collection_photos',  :multiple => true %>
          
          <%#= file_field_tag 'photos[]', :id => 'photos',  :multiple => true %>

          <%#*<input id="cultural_heritage_collection_photo" multiple="multiple" name="cultural_heritage_collection[photo][]" type="file">%>
          <%#= f.input :photos, :as => :file, :input_html => {:multiple => true} %>
          <%#= f.file_field :photo, {:multiple => 'multiple'} %>
        <%#*</div>%>

      </fieldset>
      
  </fieldset>

  <div class="actions">
        <%= f.submit "Enviar" %>
  </div>
</div>

<% end %>

<script type="text/javascript">
  // form validation function //
  function validate(form) {
    //input
    var name = form.cultural_heritage_collection_name.value;
    //select
    var owner = form.cultural_heritage_collection_owner.value;
    //input
    var original_size = form.cultural_heritage_collection_original_size.value;
    //textarea
    var description = form.cultural_heritage_collection_description.value;
    
    //var email = form.email.value;
    //var gender = form.gender.value;
    //var message = form.message.value;

    if(name == "") {
      inlineMsg('cultural_heritage_collection_name','Debe ingresar un nombre para la colección.',3);
      return false;
    };
    if(!name.match(nameRegex)) {
      inlineMsg('cultural_heritage_collection_name','Debe de ingresar un nombre válido.',3);
      return false;
    };
    if(owner == "") {      
      inlineMsg('cultural_heritage_collection_owner','Debe seleccionar un propietario para la colección.',3);
      return false;
    };    
    if(original_size.match(num_regex) == null) {
      inlineMsg('cultural_heritage_collection_original_size','Debe ingresar un valor numérico positivo.',3);
      return false;
    };
    if(parseInt(original_size) <= 1) {
      inlineMsg('cultural_heritage_collection_original_size','Debe ingresar un tamaño original mayor que 1.',3);
      return false;
    };
    if(description == "") {
      inlineMsg('cultural_heritage_collection_description','Debe ingresar una decripción para la colección.',3);
      return false;
    };
    if(description.match(messageRegex)) {
      inlineMsg('cultural_heritage_collection_description','Debe ingresar una decripción válida.',3);
      return false;
    };
    
    /*
    if(email == "") {
      inlineMsg('email','<strong>Error</strong><br />You must enter your email.',3);
      return false;
    };
    if(!email.match(emailRegex)) {
      inlineMsg('email','<strong>Error</strong><br />You have entered an invalid email.',3);
      return false;
    };
    if(gender == "") {
      inlineMsg('gender','<strong>Error</strong><br />You must select your gender.',3);
      return false;
    };
    if(message == "") {
      inlineMsg('message','You must enter a message.');
      return false;
    };
    if(message.match(messageRegex)) {
      inlineMsg('message','You have entered an invalid message.');
      return false;
    };
    */
  };

</script>
